package com.say.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.say.test.R;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		addButtonshowPackageName();
	}
	
	
	private void addButtonshowPackageName(){
		ViewGroup vg;
		vg= (ViewGroup) ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0); 
		Button but = new Button(this);
	
		but.setText("显示包名");
		but.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				String packageName = MainActivity.this.getApplicationInfo().packageName;
				String processName = MainActivity.this.getApplicationInfo().processName;
				toast("packageName:" + packageName);
				toast("processName:" + processName);
			}
		});
		ViewGroup.LayoutParams lp = 
				new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
		vg.addView(but,lp);
	}
	
	public void toAnotherActivity(View v) {
		switch (v.getId()) {
		case R.id.btn_to_listview_activity:
			Intent intent1= new Intent(MainActivity.this, DBOperateActivity.class);
			startActivity(intent1);
			break;
		case R.id.btn_to_dialogs_activity:
			Intent intent2= new Intent(MainActivity.this, DialogsActivity.class);
			startActivity(intent2);
			break;
		case R.id.btn_to_dialog_activity:
			Intent intent3= new Intent(MainActivity.this, DemoDialogActivity.class);
			startActivity(intent3);
			break;
		case R.id.btn_show_dialog:
			DialogBox box =	new DialogBox(this);
			box.setDialog(new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					toast("confirm111");
				}
			}, new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					toast("cancel222");
				}
			});
			box.buildTipDialog().show();
			break;
		case R.id.btn_to_download_activity:
			Intent intent4= new Intent(MainActivity.this, DownloadActivity.class);
			startActivity(intent4);
			break;
		case R.id.btn_to_findsth:
			Intent intent5= new Intent(MainActivity.this, FindSthActivity.class);
			startActivity(intent5);
			break;
		case R.id.btn_to_Notification:
			Intent intent6= new Intent(MainActivity.this, NotifyActivity.class);
			startActivity(intent6);
			break;
		default:
			break;
		}
	
	}
	
	private void toast(String string) {
		Toast.makeText(MainActivity.this, string, Toast.LENGTH_SHORT).show();
	}
}
